Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: improve physical planning of window functions #85355

Merged
merged 2 commits into from
Aug 1, 2022

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Jul 30, 2022

sql: remove shouldNotDistribute recommendation

It doesn't seem to be used much.

Release note: None

sql: improve physical planning of window functions

This commit improves the physical planning of window functions in
several ways.

First, the optimizer is updated so that all window functions with a
PARTITION BY clause are constructed first followed by the remaining
window functions without PARTITION BY. This is needed by the execution
which can only evaluate functions with PARTITION BY in the distributed
fashion - as a result of this change, we are now more likely to get
partial distributed execution (previously things depended on the order
in which window functions were mentioned in the query).

Second, the physical planner now thinks that we "should distribute" the
plan if it finds at least one window function with PARTITION BY clause.
Previously, we didn't make any recommendation about the distribution
based on the presence of the window functions (i.e. we relied on the
rest of the plan to do so), but they can be quite computation-intensive,
so whenever we can distribute the execution, we should do so.

Additionally, this commit removes some of the code in the physical
planner which tries to find window functions with the same PARTITION BY
and ORDER BY clauses - that code has been redundant for long time given
that the optimizer does that too.

Release note: None

It doesn't seem to be used much.

Release note: None
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich force-pushed the wf branch 6 times, most recently from 58a4065 to 732b206 Compare August 1, 2022 16:09
@yuzefovich yuzefovich marked this pull request as ready for review August 1, 2022 16:09
@yuzefovich yuzefovich requested a review from a team August 1, 2022 16:09
@yuzefovich yuzefovich requested a review from a team as a code owner August 1, 2022 16:09
Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring!

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rytaft and @yuzefovich)


pkg/sql/distsql_physical_planner.go line 3760 at r2 (raw file):

	// Check that all window functions have the same PARTITION BY and ORDER BY
	// clauses.

[nit] Maybe add a comment mentioning that the optbuilder ensures that all window functions in the node have the same PARTITION BY and ORDER BY clauses.

This commit improves the physical planning of window functions in
several ways.

First, the optimizer is updated so that all window functions with a
PARTITION BY clause are constructed first followed by the remaining
window functions without PARTITION BY. This is needed by the execution
which can only evaluate functions with PARTITION BY in the distributed
fashion - as a result of this change, we are now more likely to get
partial distributed execution (previously things depended on the order
in which window functions were mentioned in the query).

Second, the physical planner now thinks that we "should distribute" the
plan if it finds at least one window function with PARTITION BY clause.
Previously, we didn't make any recommendation about the distribution
based on the presence of the window functions (i.e. we relied on the
rest of the plan to do so), but they can be quite computation-intensive,
so whenever we can distribute the execution, we should do so.

Additionally, this commit removes some of the code in the physical
planner which tries to find window functions with the same PARTITION BY
and ORDER BY clauses - that code has been redundant for long time given
that the optimizer does that too.

Release note: None
Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball and @rytaft)


pkg/sql/distsql_physical_planner.go line 3760 at r2 (raw file):

Previously, DrewKimball (Drew Kimball) wrote…

[nit] Maybe add a comment mentioning that the optbuilder ensures that all window functions in the node have the same PARTITION BY and ORDER BY clauses.

Done.

@craig
Copy link
Contributor

craig bot commented Aug 1, 2022

Build succeeded:

@craig craig bot merged commit 314baa5 into cockroachdb:master Aug 1, 2022
@yuzefovich yuzefovich deleted the wf branch August 1, 2022 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants